package com.gitee.grower.core.scheme

import ac.github.oa.internal.core.item.ItemPlant
import com.gitee.grower.ItemGrower
import com.gitee.grower.ItemGrowerAPI.countItem
import com.gitee.grower.core.kether.toKetherInt
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.common.util.replaceWithOrder
import taboolib.library.configuration.ConfigurationSection
import taboolib.platform.util.buildItem

interface Item {

    val amountScript: String

    fun buildIcon(player: Player) : ItemStack

    class Default(val id: String,override val amountScript: String) : Item {

        override fun buildIcon(player: Player): ItemStack {
            return ItemPlant.build(player,id)!!
        }

    }

    class Condition(val config: ConfigurationSection) : Item {

        val id = config.name
        override val amountScript = config.getString("amount","1")!!
        val name = config.getString("name",id)!!
        val remark = config.getString("remark","")!!
        val match = config.getString("match","true")!!
        val iconId = config.getString("icon.id",id)!!
        val iconVars = config.getConfigurationSection("icon.vars")?.getKeys(false)?.associate {
            it to config.getString("icon.vars.$it")!!
        } ?: emptyMap()

        override fun buildIcon(player: Player): ItemStack {
            return buildItem(ItemPlant.build(player,iconId,iconVars.toMutableMap())!!) {
                this.name += " &f$remark"
            }
        }


    }

}